﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Events;
using Infrastructure.Events;
using System.ComponentModel;
using ALPShell.ViewModel;

namespace ALPShell
{
    /// <summary>
    /// Interaction logic for LogonWindow.xaml
    /// </summary>
    public partial class LogonWindow : Window
    {
        IEventAggregator eventAggregator;
        bool keepAlive = false;

        public LogonWindow(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
            eventAggregator.GetEvent<KillAppEvent>().Subscribe(e =>
            {
                keepAlive = e.IsKeptAlive;

                Close();
            });

            InitializeComponent();
        }


        private void OnClosing(object sender, CancelEventArgs e)
        {
            if (((this.DataContext as LogonWindowViewModel).IsSwitchUser)) return;
            if (!keepAlive)
            {
                Application.Current.Shutdown(99);
            }
        }
    }
}
